home *** CD-ROM | disk | FTP | other *** search
- #include "Chimer.h"
- #include "Sound.h"
- #include "stddef.h"
-
- SndChannelPtr gChan1, gChan2, gChan3, gLastChan;
-
- extern short MasterVolume;
-
- // Thank you Jim Reekes, for helpful guidance
-
- OSErr InitChimer(void)
- {
- SndCommand cmd;
- SndListHndl snd,snd2;
- OSErr err;
-
- gChan1 = nil;
- gChan2 = nil;
- gChan3 = nil;
-
- ////// Get the CHIME sound from my resources
- snd = (SndListHndl)GetResource('snd ', 1000);
- if (snd == nil)
- return (ResError());
-
- // This builds a sound manager command that installs the sound as the
- // synthesizer voice
- HLock((Handle)snd);
- cmd.cmd = soundCmd;
- cmd.param2 = (long)((long)(*snd) + offsetof(SndListResource, dataPart));
-
- // Now stuff the command into each of the first two channels
- err = SndNewChannel(&gChan1, sampledSynth, 0, nil);
- if (err != noErr)
- return (err);
- err = SndDoImmediate(gChan1, &cmd);
-
- // I have no idea why I'm stuffing the address of the sound into a
- // userinfo (for the application's use) field
- // I got the bits from Reekes and I forget why
- gChan1->userInfo = cmd.param2;
-
- err = SndNewChannel(&gChan2, sampledSynth, 0, nil);
- if (err != noErr)
- return (err);
- err = SndDoImmediate(gChan2, &cmd);
-
- ////// Get the CHUNK sound from my resources
- snd2 = (SndListHndl)GetResource('snd ', 1001);
- if (snd2 == nil)
- return (ResError());
-
- // This builds a sound manager command that installs the sound as the
- // synthesizer voice
- HLock((Handle)snd2);
- cmd.cmd = soundCmd;
- cmd.param2 = (long)((long)(*snd2) + offsetof(SndListResource, dataPart));
-
- // Now stuff the command into the third channel
- err = SndNewChannel(&gChan3, sampledSynth, 0, nil);
- if (err != noErr)
- return (err);
- err = SndDoImmediate(gChan3, &cmd);
-
- // I have no idea why I'm stuffing the address of the sound into a
- // userinfo (for the application's use) field
- // I got the bits from Reekes and I forget why
- gChan3->userInfo = cmd.param2;
-
- return (noErr);
- }
-
-
- void PlayAChime(short chime)
- {
- SndCommand cmd;
- short note;
- OSErr err;
-
- switch (chime)
- {
- case 1:
- gLastChan = gChan1;
- note = 55;
- break;
-
- case 2:
- gLastChan = gChan1;
- note = 57;
- break;
-
- case 3:
- gLastChan = gChan2;
- note = 60;
- break;
-
- case 4:
- gLastChan = gChan2;
- note = 65;
- break;
-
- case 5:
- gLastChan = gChan2;
- note = 67;
- break;
-
- case 6:
- gLastChan = gChan3;
- note = 60;
- break;
- }
-
- // First send a command that tells how loud to make the sound
- cmd.cmd = ampCmd;
- cmd.param1 = (Random() & 0x7FFF) % 5;
- cmd.param1 = (cmd.param1 + 1) * MasterVolume;
- err = SndDoImmediate(gLastChan, &cmd);
-
- // why is this here? to prevent playing?
- cmd.cmd = quietCmd;
- err = SndDoImmediate(gLastChan, &cmd);
-
- // Put a command in the queue to play the sound
- // The frequency is the midi note number set above in the case statement
- // The duration is set to 1/4 second
- cmd.cmd = freqDurationCmd;
- cmd.param1 = 500;
- cmd.param2 = note;
- err = SndDoCommand(gLastChan, &cmd, true);
-
- // After the above command is complete, tell the synth to shut up
- // If you don't, it'll just keep playing the same note.
- cmd.cmd = quietCmd;
- err = SndDoCommand(gLastChan, &cmd, true);
-
- }
-
-
-